#include <stdio.h>
#include <stdlib.h>

#include "mainwindow.h"
#include "controller.h"
#include <QLayout>
#include <QMenuBar>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
     menuBar = new QMenuBar(this);

     QAction* newGame = new QAction("New game", this);
     connect(newGame, SIGNAL(triggered()), this, SLOT(init()));
     menuBar->addAction(newGame);

     this->setMenuBar(menuBar);
     init();
}

void MainWindow::init()
{
    gameScene = new Controller();
    connect(gameScene, SIGNAL(updateScore(int)), this, SLOT(updateScore(int)));
    gameView = new QGraphicsView(gameScene);
    setCentralWidget(gameView);

    statusBar = new QStatusBar();
    QLabel* descr = new QLabel("Score: ");
    score = new QLabel("0");
    statusBar->addWidget(descr);
    statusBar->addWidget(score);
    setStatusBar(statusBar);
    layout()->setSizeConstraint(QLayout::SetFixedSize);
    gameView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    gameView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void MainWindow::updateScore(int val)
{
    QString s;
    s.setNum(val);
    score->setText(s);
}
